package api

import (
	"github.com/gin-gonic/gin"
	"zsc-boot/app/system_layer/model"
	"zsc-boot/core/orm"
	"zsc-boot/core/web"
)

func GetCityList(ctx *gin.Context) {
	name := ctx.Query("name")
	parentId := ctx.Query("parentId")

	db := orm.GetDb().Model(&model.ServiceCity{})
	if name != "" {
		db = db.Where("name like ?", "%"+name+"%")
	}
	if parentId != "" {
		db = db.Where("parent_id = ?", parentId)
	}

	var cityList []model.ServiceCity
	if err := db.Find(&cityList).Error; err != nil {
		web.FailResponse(ctx, err, "查询失败")
		return
	}

	web.SuccessResponse(ctx, cityList)
}
